<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"/>
		<title>改变this指向</title>
	</head>
	<body>
		<script type="text/javascript">
		//箭头函数
/* 		console.log(this);
		var student = {
			name:"子明",
			fn:() =>{
				console.log(this);
				console.log(this.name);
				console.log(this.name+"喜欢吃烤鸡");//this指向上一层对象
			}
		} */
		

		//apply和call
/* 		var student = {
			name:"子明",
			like:function(){
				console.log(this);
				console.log(this.name+"喜欢吃烧鸡");
				for(var i = 0; i < arguments.length;i++){
					console.log(this.name+"喜欢"+arguments[i]);
				}
			}
		}

		var teacher = {
			name:"子房"
		}

		var fn= student.like;
		//fn.call(student,"唱","跳","rap");//this-->student
		fn.apply(teacher,["唱", "跳", "rap"]);//this-->teacher */
		


		//bind
/* 		var teacher = {
			name:"子房"
		}

		var student = {
			name:"子明",
			like:function(){
				console.log(this.name+"喜欢吃烤鸡");
			}.bind(teacher)
		};

		var fn = function(){
			console.log(this);
			console.log(this.name+"喜欢吃烧鸡");
			for(var i = 0; i <arguments.length;i++){
				console.log(this.name+"喜欢"+arguments[i]);
			};
		}.bind(student);

		fn();//this-->student
		student.like();//this-->teacher */
		
		
		</script>
	</body>
</html>